<?php

namespace Qwadmin\Model;

class ReferlinkModel extends \Think\Model{
    public  function __construct() {
        
    }
    
    public function getList($where, $page = 1 ){
        $prefix = C("DB_PREFIX");
        $pageSize = 10 ;
        $offset = $pageSize * ($page - 1); //计算记录偏移量
        $count =M("referral_links")->join("left join {$prefix}bookinfo on {$prefix}bookinfo.id = bookid")
                 ->where($where)->count("uid");
        $pagebar = new \Think\Page($count , $pageSize);
        
        $list = M("referral_links")->join("left join {$prefix}bookinfo on {$prefix}bookinfo.id = bookid")
                ->join("left join {$prefix}bookchapter on {$prefix}bookchapter.id = chapterid")
                ->field("bookid,{$prefix}referral_links.id,"
                . "{$prefix}referral_links.description,{$prefix}bookinfo.book_title,"
                . "{$prefix}bookchapter.chapter_name,created,hits,newuser,newsubs,amount")
                ->where($where)
                ->order("created desc")
                ->limit($offset . ',' . $pageSize )
                ->select();
       
        return [
            'list'  => $list,
            'page'  => $pagebar->show()
        ];
    }
    
    
}
